package com.ztsoft.user.controller.dynamic;

import com.ztsoft.user.pojo.enums.ResultCode;
import com.ztsoft.user.service.dynamic.MetaTableService;
import com.ztsoft.user.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@CrossOrigin("*")
@RestController
@RequestMapping(value = "/metaTable")
@Api(tags = "库表元数据")
public class MetaTableController {

    @Resource(name = "metaTableService")
    private MetaTableService metaTableService;

    //获取表名
    @RequestMapping("/listTables")
    @ApiOperation(value = "获取表名")
    public Result<Object> listTables() {
        List<String> list = metaTableService.listTables();
        return Result.returnDataMsg(ResultCode.SUCCESS.getMsg(), ResultCode.SUCCESS.getCode(), list);
    }

    //获取指定表的字段-映射
    @RequestMapping("/listTableColumn")
    @ApiOperation(value = "获取指定表的字段-映射")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tableName", value = "数据库表名", required = true, paramType = "form"),
            @ApiImplicitParam(name = "tableCode", value = "表格编码", required = true, paramType = "form")
    })
    public Result listTableColumn(String tableName, String tableCode, String deptId) {
        List<Map> list = metaTableService.listTableColumn(tableName, tableCode, deptId);
        return Result.returnDataMsg(ResultCode.SUCCESS.getMsg(), ResultCode.SUCCESS.getCode(), list);
    }

}
